package cn.qyd.atomic;

import cn.qyd.common.Person;
import org.checkerframework.checker.units.qual.A;

import java.util.concurrent.atomic.*;

/**
 * @author 邱运铎
 * @date 2024-03-24 20:52
 */
public class AtomicDemo {
    public static void main(String[] args) {
        AtomicInteger atomicInteger = new AtomicInteger(1);
        //先获得旧值，再自增
        System.out.println(atomicInteger.getAndIncrement());
        //自增后再获得新值
        System.out.println(atomicInteger.incrementAndGet());
        AtomicLong atomicLong = new AtomicLong(1L);
        AtomicBoolean atomicBoolean = new AtomicBoolean(true);
        AtomicIntegerArray atomicIntegerArray = new AtomicIntegerArray(10);
        AtomicLongArray atomicLongArray = new AtomicLongArray(10);
        AtomicReferenceArray<String> stringAtomicReferenceArray = new AtomicReferenceArray<>(10);
        AtomicReference<Person> qyd = new AtomicReference<>(new Person("qyd", 18));
        System.out.println(qyd.getAndSet(new Person("qyd1",19)));
        AtomicIntegerFieldUpdater<Person> age = AtomicIntegerFieldUpdater.newUpdater(Person.class, "age");
        AtomicLongFieldUpdater<Person> num = AtomicLongFieldUpdater.newUpdater(Person.class, "num");
        AtomicStampedReference<Person> st = new AtomicStampedReference<>(new Person("qiuyunduo",19),1);
        AtomicMarkableReference<String> markableReference = new AtomicMarkableReference<>("Hello World1",true);
    }
}
